<template>
    <div>
        <el-table :data="couponList" size="mini" header-cell-class-name="tableHeaderStyle" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="type" :formatter="formatType" label="券类型"></el-table-column>
            <el-table-column prop="title" label="标题"></el-table-column>
            <el-table-column prop="remainQuantity" label="剩余数量"></el-table-column>
            <el-table-column prop="expiryTime" label="过期时间"></el-table-column>
            <el-table-column prop="status" :formatter="formatCouponStatus" label="状态"></el-table-column>
        </el-table>
    </div>
</template>

<script>

import {getCouponByPage} from "@/api/api";

export default {
    name: "coupon",
    data() {
        return {
            couponList: [],
            couponSelected: [],
        }
    },
    // 这里定义需要父组件传过来的东西
    props: {},
    methods: {
        formatType: function (row, column, cellValue) {
            if (cellValue == 'GIFT') {
                return "兑换券";
            } else if (cellValue == 'DISCOUNT') {
                return "折扣券";
            } else if (cellValue == 'GENERAL') {
                return "优惠券";
            } else {
                return cellValue;
            }
        },
        formatCouponStatus: function (row, column, cellValue) {
            if (cellValue == 'AUDIT_SUCCEEDED') {
                return "审核成功";
            } else {
                return cellValue;
            }
        },
        handleSelectionChange(val) {
            this.couponSelected = val;
        }
    },
    created() {
        let condition = {
            page: 1,
            rows: 10,
            total: 0,
            search: {}
        };
        getCouponByPage(condition).then(data => {
            this.couponList = data.body.rows;
        });
    },
}
</script>

<style scoped>

</style>
